package com.taihe.service.impl;

import com.taihe.dao.TsPlatformUserMapper;
import com.taihe.domain.TsPlatformUser;
import com.taihe.domain.TsPlatformUserExample;
import com.taihe.service.TsPlatformUserService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by zwt on 2018/7/24.
 */
@Service
public class TsPlatformUserServiceImpl implements TsPlatformUserService {

    @Autowired
    private TsPlatformUserMapper tsPlatformUserMapper;

    @Override
    public TsPlatformUser queryByOpenId(String openId) {
        TsPlatformUserExample tsPlatformUserExample = new TsPlatformUserExample();
        TsPlatformUserExample.Criteria criteria = tsPlatformUserExample.createCriteria();
        criteria.andOpenIdEqualTo(openId);
        List<TsPlatformUser> tsPlatformUsers = tsPlatformUserMapper.selectByExample(tsPlatformUserExample);
        if(CollectionUtils.isNotEmpty(tsPlatformUsers) && tsPlatformUsers.size()==1){
            return tsPlatformUsers.get(0);
        }
        return null;
    }

    @Override
    public int insert(TsPlatformUser user) {
        return tsPlatformUserMapper.insertSelective(user);
    }

    @Override
    public List<TsPlatformUser> selectAll() {
        TsPlatformUserExample tsPlatformUserExample = new TsPlatformUserExample();
        List<TsPlatformUser> tsPlatformUsers = tsPlatformUserMapper.selectByExample(tsPlatformUserExample);
        return tsPlatformUsers;
    }
}
